//
//  ShopDetailViewController.swift
//  worldexchange
//
//  Created by xionghao on 2019/2/18.
//  Copyright © 2019 xionghao. All rights reserved.
//

import UIKit

class ShopDetailViewController: QMUICommonViewController {

    @IBOutlet weak var webView: WKWebView!

    var shopItem:ShopItem!
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        setupHtmlData(item: shopItem)
    }

    func setupHtmlData(item:ShopItem)  {
        
        self.showEmptyViewWithLoading()
        let locale = LanguageHelper.shareInstance.locale
        let fileName =  "shop"
        let path = Bundle.main.path(forResource: fileName, ofType: "html")
        var htmlstring = try! String(contentsOfFile:  path!, encoding: String.Encoding.utf8)

        self.title = LanguageHelper.getString(key: "BranchDetail")
        htmlstring =  htmlstring.replacingOccurrences(of: "{{logo}}", with: item.image)
        htmlstring =  htmlstring.replacingOccurrences(of: "{{map}}", with: item.images)
        htmlstring = htmlstring.replacingOccurrences(of: "{{content}}", with: item.content)
        htmlstring = htmlstring.replacingOccurrences(of: "{{shop_name}}", with: item.title)
        htmlstring = htmlstring.replacingOccurrences(of: "{{call}}", with: item.ex_title)
        htmlstring = htmlstring.replacingOccurrences(of: "{{address}}", with: item.eaddress)
        htmlstring = htmlstring.replacingOccurrences(of: "{{workday}}", with: item.eex_title)
        htmlstring = htmlstring.replacingOccurrences(of: "{{saturday}}", with: item.tex_title)
        htmlstring = htmlstring.replacingOccurrences(of: "{{sunday}}", with: LanguageHelper.getString(key: item.taddress))
        htmlstring = htmlstring.replacingOccurrences(of: "{{workday_tips}}", with: LanguageHelper.getString(key: "textWorkDay"))
        htmlstring = htmlstring.replacingOccurrences(of: "{{saturday_tips}}", with: LanguageHelper.getString(key: "textSaturday"))
        htmlstring = htmlstring.replacingOccurrences(of: "{{sunday_tips}}", with: LanguageHelper.getString(key: "textSunday"))
        htmlstring = htmlstring.replacingOccurrences(of: "{{call_tips}}", with: LanguageHelper.getString(key: "textCall"))
        htmlstring = htmlstring.replacingOccurrences(of: "{{address_tips}}", with: LanguageHelper.getString(key: "textAddress"))



        let baseUrl = URL(string: HOST_URL)!
        self.webView.loadHTMLString(htmlstring, baseURL: baseUrl)
        self.hideEmptyView()
    }


    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
